import {Component, OnInit} from '@angular/core';
import {FormBuilder, FormGroup, Validators} from "@angular/forms";
import {Observable} from "rxjs";
import {ActivatedRouteSnapshot, RouterStateSnapshot} from "@angular/router";
import {MessageUtilService} from "great-zorroutils";

@Component({
  selector: 'app-form-form-leave',
  templateUrl: './form-leave.component.html',
})
export class FormFormLeaveComponent implements OnInit {

  formGrop: FormGroup;

  constructor(
    private fb: FormBuilder,
    private messageService: MessageUtilService,
  ) {
    this.formGrop = this.fb.group({
      userName: ['', [Validators.required]],
      email: ['', [Validators.email, Validators.required]],
      password: ['', [Validators.required]],
      confirm: ['',],
      comment: ['', [Validators.required]]
    });
  }

  ngOnInit() {
  }

  canDeactivate(
    component?: any,
    currentRoute?: ActivatedRouteSnapshot,
    currentState?: RouterStateSnapshot,
    nextState?: RouterStateSnapshot): Observable<boolean> | boolean {
    if(this.formGrop.dirty){
      return this.messageService.confirm();
    }else{
      return true;
    }
  }

}
